function WiSiL_plotPowerSpectralDensity(filename)
% WISIL_PLOTPOWERSPECTRALDENSITY Plot PSD graph from WiSiL results.
%
%   WiSiL_plotPowerSpectralDensity( FILENAME ) gets the results pre-saved 
%   in file FILENAME and uses them to plot the PSD of the transmitted
%   signal: 
%   - [ Power Spectral Density PSD(dB) ] X [ Frequency f - f_c(Hz) ]
%   Welch's averaged modified periodogram method for spectral estimationis
%   used. The last sample of the transmitted signal is divided into 80
%   segments. Each window has an overlap of 50%half of the samples are
%   common to two adjacent segments). A Hamming window is used in order to
%   reduce the spectral leakage
%   
%   WiSiL_plotPowerSpectralDensity() gets the results from file
%   'results.mat'.

% 
% Wilson Diniz Wellisch, 29/10/2010
%   created
% Andre Noll Barreto, 03/04/2011
%   included file name option


if ~exist('filename', 'var')
    filename = 'results';
end
load (filename);


size_frame = size(serialSignalTx,2);

size_window = floor(size_frame/80);

[X,f] = pwelch( serialSignalTx(1,:), hamming(size_window), ...
                floor(size_window/2), [], param.frame.samplingFreq, ...
                'twosided' );

X = fftshift(X);
X = 10*log10(X);

f = f - param.frame.samplingFreq/2;

figure;
plot(f,X)
grid on
xlabel('Frequency f - f_c(Hz)');
ylabel('Power Spectral Density PSD(dB)');